/*

Version:
Author: LH Software Group
Copyright
*/

#include "spi_port.h"


void stm_lh_spi_init()
{

}

uint8_t drv_spi_read_write_byte( uint8_t TxByte )
{
	uint8_t i = 0, Data = 0;
	
	spi_set_clk_low( );
    
	SPI_DELAY;
    
	for( i = 0; i < 8; i++ )
	{
		spi_set_clk_high( );
        
		if( 0x80 == ( TxByte & 0x80 ))
		{
			spi_set_mosi_hight( );
		}
		else
		{
			spi_set_mosi_low( );
		}
		TxByte <<= 1;
        
		SPI_DELAY;

		spi_set_clk_low( );
		;
        
		Data <<= 1;
		if( 1 == spi_get_miso( ))
		{
			Data |= 0x01;
		}
        
		SPI_DELAY;
	}
	
	return Data;
}

uint8_t stm_lh_spi_txrx8bit(uint8_t tx_byte)
{
//     /*!< Loop while DR register in not empty */
//  while(RESET == spi_i2s_flag_get(SPI0, SPI_FLAG_TBE));

//  /*!< Send byte through the SPI1 peripheral */
//  spi_i2s_data_transmit(SPI0, tx_byte);

//  /*!< Wait to receive a byte */
//  while(RESET == spi_i2s_flag_get(SPI0, SPI_FLAG_RBNE));

//  /*!< Return the byte read from the SPI bus */
//  return spi_i2s_data_receive(SPI0);

    return drv_spi_read_write_byte(tx_byte);
}


void stm_lh_delay_10us()
{
    platform_delay_us(10);
}
